<%--
  Created by IntelliJ IDEA.
  User: zk
  Date: 2017/11/9
  Time: 10:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>

<blockquote class="layui-elem-quote">${title}</blockquote>
<div class="layui-row">
    <div class="layui-col-xs12 layui-col-md4">
        <div id="tree"></div>
    </div>
    <div class="layui-col-xs12 layui-col-md7 layui-col-md-offset1">
        <form class="layui-form" action="${ctx}/sys/menu/save" data-pjax>
            <div class="layui-form-item">
                <label class="layui-form-label ">父级菜单</label>
                <div class="layui-input-block ">
                    <input type="text" id="parentName" autocomplete="off" class="layui-input" readonly placeholder="请从左侧选择父菜单" value="${menu.parentName}">
                    <input type="hidden" value="${menu.parentId}" name="parentId" id="parentId">
                    <input type="hidden" value="${menu.id}" name="id">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label ">菜单名称</label>
                <div class="layui-input-block ">
                    <input value="${menu.name}" type="text" name="name" lay-verify="required" lay-verType="tips" placeholder="请输入菜单名称" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label ">菜单链接</label>
                <div class="layui-input-block ">
                    <input value="${menu.href}" s name="href"  placeholder="请输入菜单链接" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label ">菜单图标</label>
                <div class="layui-input-block ">
                    <input value="${menu.icon}" type="text" name="icon"  placeholder="请输入菜单图标" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label ">权限名称</label>
                <div class="layui-input-block ">
                    <input value="${menu.permission}" type="text" name="permission"  placeholder="请输入权限名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label ">排序值</label>
                <div class="layui-input-block ">
                    <input
                    <c:if test="${maxSort eq null}"> value="${menu.nodeValue}"</c:if>
                    <c:if test="${maxSort ne null}"> value="${maxSort}"</c:if>
                                   type="text" name="nodeValue" lay-verify="required|nodeValue" lay-verType="tips" placeholder="请输入排序值" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label ">显示状态</label>
                <div class="layui-input-block">
                    <c:if test="${menu.isShow eq '0'}">
                        <input type="radio" name="isShow" value="0" title="显示" checked>
                        <input type="radio" name="isShow" value="1" title="不显示">
                    </c:if>
                    <c:if test="${menu.isShow eq '1' or menu.isShow eq null}">
                        <input type="radio" name="isShow" value="0" title="显示" >
                        <input type="radio" name="isShow" value="1" title="不显示" checked>
                    </c:if>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block ">
                    <button class="layui-btn " lay-submit="" lay-filter="">保存</button>
                    <a class="layui-btn layui-btn-primary" href="${ctx}/sys/menu/" data-pjax>返回</a>
                </div>
            </div>
        </form>
    </div>
</div>

<script>
//    layui.use(['form','jquery','element'],function(){
//        //无需再执行layui.use()方法加载模块，直接使用即可
//
//    });
$(function(){
        var form = layui.form;
        form.verify({
            //我们既支持上述函数式的方式，也支持下述数组的形式
            //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
            nodeValue: [
                /^[1-9][0-9][0-9]{1}$/
                ,'排序值必须在100至999之间，且不能出现空格'
            ]
        });
        form.render();
        ajaxPost('${ctx}/sys/menu/treeData', {
            'defaultSelectedId': '${menu.parentId}'
        },function(respData){
            $('#tree')
                .treeview({data: respData})
                .treeview('expandAll', { levels: 2, silent: true })
                .on('nodeSelected', function(event, data) {
                    $('#parentId').val(data.pid);
                    $('#parentName').val(data.text);
                });
        });
});
</script>